package com.bdsoft.actions.UserManage.Controller;

import cn.hutool.core.util.StrUtil;
import com.bdsoft.actions.AcUrls;
import com.bdsoft.actions.UserManage.DTO.UserDTO;
import com.bdsoft.actions.UserManage.Service.UserService;
import com.github.xiaoymin.knife4j.annotations.Ignore;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;

import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(AcUrls.UserManage.userManageUrl)
@Tag(name = "用户相关接口")

public class UserController {
    @Autowired
    UserService userService;

    @Operation(summary = "获得用户分页树形结构",security = { @SecurityRequirement(name = HttpHeaders.AUTHORIZATION) })
    @PostMapping(AcUrls.UserManage.getUserTree)
    public ResponseEntity getUserTree(@RequestParam int pageNum, @RequestParam int pageSize,@RequestParam(required = false) String id, @RequestParam(required = false) String userName,@RequestParam(required = false) String status,@RequestParam(required = false) String nickName){

        return ResponseEntity.ok(userService.getUserTree(pageNum,pageSize,id,userName,status,nickName));
    }

    @Operation(summary = "保存/修改用户",security = { @SecurityRequirement(name = HttpHeaders.AUTHORIZATION) })
    @PostMapping(AcUrls.UserManage.saveOrUpdateUser)


    public Map<String,Object> saveOrUpdateUser(@RequestBody UserDTO userDTO){

        return userService.saveOrUpdateUser(userDTO);
    }

    @Operation(summary = "删除用户")
    @PostMapping(AcUrls.UserManage.deleteUserById)

    public Map<String,Object> deleteUserById(@RequestParam String userId
    )
    {
        return userService.deleteUserById(userId);
    }
    @Operation(summary = "给用户分配角色")
    @PostMapping(AcUrls.UserManage.allocateRole)

    public Map<String,Object> allocateRole(@RequestParam String userId,String roleIds
    )
    {
        return userService.allocateRole(userId,roleIds);
    }
    @Operation(summary = "根据用户id获得角色")
    @PostMapping(AcUrls.UserManage.getRoleByRole)

    public Map<String,Object> getRoleByRole(@RequestParam String userId
    )
    {
        return userService.getRoleByRole(userId);
    }
    @Operation(summary = "给用户分配部门")
    @PostMapping(AcUrls.UserManage.setDepartment)

    public Map<String,Object> setDepartment(@RequestParam String userId,@RequestParam String departMentId
    )
    {
        return userService.setDepartment(userId,departMentId);
    }

}
